home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / asm32.zip / E32.ZIP / M_INIT.ASM < prev    next >
Assembly Source File  |  1996-08-26  |  5KB  |  322 lines

  1. ; M_INIT.ASM for E32 - Copyright (C) 1994 Douglas Herr
  2. ;  all rights reserved
  3.  
  4. include    model.inc
  5.  
  6. public    mouse_init
  7. extrn    cursoron:near
  8. extrn    ismouse:near
  9. extrn    up:near, down:near
  10. extrn    home:near, endd:near
  11. extrn    left:near, right:near
  12. extrn    extended_key:near
  13. extrn    swap_files:near, display_screen:near
  14. extrn    x0:near
  15.  
  16. include    dataseg.inc
  17. mouse_rc    dw 0
  18. old_left_margin    dw 0
  19. extrn    mouse_on:byte
  20. extrn    cur_posn:byte        ; really a word
  21. extrn    first_row:byte
  22. extrn    rows:byte, columns:word
  23. extrn    mouseflag:byte
  24. extrn    normal:byte
  25. extrn    filesel:word
  26. extrn    left_margin:word
  27. extrn    filesiz:dword, cursor:dword
  28. @curseg    ends
  29.  
  30. include    codeseg.inc
  31. mouse_init    proc    near
  32.     call    ismouse
  33.     jnc    short m0
  34.     clc
  35.     ret
  36.  
  37. ; install mouse event handler
  38. m0:
  39.     mov    ax,0
  40.     int    33h
  41.  
  42.     mov    ax,cs
  43.     mov    es,ax
  44.     lea    edx,mouse_pos
  45.     mov    ax,0Ch
  46.     mov    cx,1010101b
  47.     int    33h
  48.  
  49. ; set horizontal range for cursor
  50.     movzx    edx,columns    ; maximum character limit
  51.     mov    cl,3
  52.     cmp    dx,60
  53.     adc    cl,0
  54.     shl    edx,cl
  55.     dec    edx
  56.     xor    ecx,ecx        ; minimum
  57.     mov    ax,7
  58.     int    33h
  59.  
  60. ; set vertical range for cursor
  61.     movzx    edx,rows
  62.     inc    edx
  63. ;    inc    edx        ; allow mouse to point to function key prompts
  64.     mov    cl,3
  65.     shl    edx,cl
  66.     dec    edx
  67.     xor    ecx,ecx
  68.     mov    ax,8
  69.     int    33h
  70.     ret
  71. mouse_init    endp
  72.  
  73. mouse_pos:
  74.     test    ax,1        ; test for mouse motion
  75.     jnz    mp1        ; turn mouse on if it moved
  76.     push    fs
  77.     push    ds
  78.     mov    ax,_NEAR
  79.     mov    ds,ax
  80.     assume    ds:_NEAR
  81.  
  82.     mov    ax,left_margin
  83.     mov    old_left_margin,ax
  84.  
  85.     mov    fs,filesel
  86.     mov    ax,cx
  87.     mov    cl,3
  88.     shr    dx,cl        ; vertical
  89.     cmp    columns,60    ; adjust shift factor if 40-column screen
  90.     adc    cl,0
  91.     shr    ax,cl
  92.     xchg    ax,dx
  93.     mov    dh,al
  94.  
  95. ; check to see if the mouse is on the prompt row
  96.     mov    ah,rows
  97.     cmp    dh,ah        ; DH > AH?
  98.     ja    prompt
  99.  
  100. ; check for cursor at or above file's first row
  101.     mov    ah,first_row
  102.     dec    ah
  103.     cmp    al,ah
  104.     jb    file_swap
  105.     je    at_top_row
  106.  
  107.     mov    mouse_rc,dx    ; save mouse cursor position
  108.  
  109.     sub    al,cur_posn+1
  110.     movsx    ecx,al
  111.     or    al,al
  112.     jz    short column
  113.     jns    short go_down
  114.     neg    ecx
  115.  
  116.     even
  117. go_up:    push    ecx
  118.     call    up
  119.     pop    ecx
  120.     loop    go_up
  121.     jmp    short column
  122.  
  123.     even
  124. go_down:push    ecx
  125.     call    down
  126.     pop    ecx
  127.     loop    go_down
  128.  
  129. column:
  130.     movzx    ecx,byte ptr mouse_rc
  131.     movzx    eax,cur_posn
  132.     sub    ecx,eax
  133.     jz    short set_cursor
  134.     js    short mouse_left
  135.  
  136. ; go right as long as the cursor is to the left of the mouse
  137. mouse_right:
  138.     call    right
  139.     mov    eax,cursor
  140.     cmp    eax,filesiz
  141.     jae    short set_cursor
  142.     mov    ax,mouse_rc    ; AH = row, AL = column
  143.     cmp    ah,cur_posn+1    ; shoud be equal
  144.     je    short mr0
  145.     call    left            ; else go back
  146.     jmp    short set_cursor    ;  & done
  147. mr0:
  148.     cmp    al,cur_posn    ; current column position
  149.     ja    mouse_right
  150.     jmp    short set_cursor
  151.  
  152. ; go left as long as the cursor is to the right of the mouse
  153. mouse_left:
  154.     call    left
  155.     mov    al,byte ptr mouse_rc
  156.     cmp    al,cur_posn
  157.     jb    mouse_left
  158.  
  159. set_cursor:
  160. ; set cursor position
  161.     mov    dx,word ptr cur_posn
  162.     xor    bh,bh
  163.     mov    ah,2
  164.     int    10h
  165.  
  166.     mov    mouse_on+1,1
  167.     pop    ds
  168.     pop    fs
  169.     assume    DS:nothing
  170.     retf
  171.  
  172. ; turn mouse cursor on if it moved
  173. mp1:    push    ds
  174.     mov    ax,_NEAR
  175.     mov    ds,ax
  176.     assume    ds:_NEAR
  177.     cmp    mouseflag,3
  178.     ja    short mp2
  179.     mov    ax,1
  180.     int    33h
  181.     mov    ds:mouse_on,1    ; update flag in E32's data area
  182. mp2:    pop    ds
  183.     retf
  184.  
  185. ;
  186. ; switch files if button clicked on inactive file
  187. ; operates by stuffing Ctrl-F7 into keyboard buffer
  188. ; works OK with GetKey
  189. ;
  190. file_swap:
  191.     xor    ecx,ecx
  192.     mov    ch,64h
  193.     mov    ah,5
  194.     int    16h
  195.     pop    ds
  196.     pop    fs
  197.     retf
  198.  
  199. ;
  200. ; mouse cursor at file header
  201. ; check for cursor at 'R' or 'C'
  202. at_top_row:
  203.     push    es
  204.     push    ds
  205.     pop    es
  206.  
  207. ;    call    mgetchr
  208. ;
  209. ;    cmp    al,'R'
  210. ;    je    short next_row
  211. ;    cmp    al,'C'
  212. ;    je    short next_column
  213. top_row_exit:
  214.     pop    es
  215.     pop    ds
  216.     pop    fs
  217.     retf
  218.  
  219. next_row:
  220.     call    down
  221.     jmp    top_row_exit
  222.  
  223. next_column:
  224.     call    right
  225.     jmp    top_row_exit
  226.  
  227.  
  228. shiftkey equ 3
  229. ctrl    equ 4
  230. altb    equ 8
  231.  
  232. prompt:
  233.     call    mgetchr        ; get character & attribute
  234. ;    inc    dl
  235.     cmp    ah,normal    ; is it in 'Fxx' area?
  236.     jne    short look_for_F
  237.     inc    dl        ; right until edge of screen or AH = inverse
  238.     cmp    dl,byte ptr columns
  239.     jb    prompt
  240. too_far_right:
  241.     dec    dl
  242.     call    mgetchr
  243.     cmp    ah,normal
  244.     je    too_far_right
  245.  
  246. ; mouse is in inverse color area
  247. ; go left to 'Fxx' prompt
  248. look_for_F:
  249.     dec    dl        ; go left
  250.     call    mgetchr
  251.     cmp    ah,normal
  252.     jne    look_for_F
  253.  
  254.     cmp    al,'0'
  255.     jne    short not_ten
  256.     mov    al,'9'+1
  257. not_ten:
  258.     cmp    al,'1'
  259.     jb    short prompt_key_exit
  260.     add    al,59-'1'
  261.  
  262. ; get shift, Ctrl, Alt-key status
  263.     push    ax
  264.     mov    ax,0200h
  265.     int    16h        ; get key toggle status byte
  266.     mov    bl,al
  267.     pop    ax
  268.  
  269. ; test for ALT-key press
  270.     mov    cl,104-59
  271.     test    bl,altb
  272.     jnz    short c
  273.  
  274. ; test for CTRL-key press
  275.     mov    cl,94-59
  276.     test    bl,ctrl
  277.     jnz    short c
  278.  
  279. ; test for SHIFT-key press
  280.     mov    cl,84-59
  281.     test    bl,shiftkey
  282.     jnz    short c
  283.  
  284.     xor    cx,cx
  285. c:    add    al,cl
  286.     call    extended_key
  287.     jnc    short prompt_key_exit
  288.     jmp    x0
  289.  
  290. prompt_key_exit:
  291.     mov    dx,word ptr cur_posn
  292.     call    cursoron
  293.     pop    ds
  294.     pop    fs
  295.     retf
  296.  
  297. mgetchr:
  298. ; get character & attribute at mouse cursor position
  299.     push    edx
  300.     mov    ax,word ptr cur_posn
  301.     push    eax
  302.     mov    ah,2        ; move cursor to (0,0)
  303.     mov    bh,0        ; page 0
  304.     int    10h
  305.     mov    ah,8        ; get char and attr
  306.     int    10h
  307.     pop    edx
  308.  
  309. ; save char & attr
  310. ; put cursor back where it was
  311.     push    eax
  312.     mov    ah,2
  313.     mov    bh,0
  314.     int    10h
  315.     pop    eax
  316.     pop    edx
  317.     ret
  318.  
  319. @curseg    ends
  320.  
  321.     end
  322.